<template>
  <div id="container">
    <el-row>
      <el-col :span="12" :offset="6">
        <el-form ref="form" :model="user" label-width="80px">
          <el-form-item label="用户">
            <el-input v-model="user.username"></el-input>
          </el-form-item>
          <el-form-item label="密码">
            <el-input type="password" v-model="user.password"></el-input>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" @click="onSubmit">登录</el-button>
            <el-button>取消</el-button>
          </el-form-item>
        </el-form>
      </el-col>
    </el-row>
  </div>
</template>

<script>
// 导入对象
import { login } from "@/api/login.js";
export default {
  // 绑定数据
  data() {
    return {
      user: { username: "", password: "" },
    };
  },
  // 函数
  methods: {
    onSubmit() {
      let that = this;
      // ajax请求
      login(this.user).then((response) => {
        if (response.data.code == "0000") {
          that.$router.push("/home");
        } else {
          that.$message.error("用户密码不正确！");
        }
      });
    },
  },
};
</script>

<style lang="scss" scoped>
#container {
}
</style>>
